package run;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import networkTraining.DataSet;
import networkTraining.IDataSet;

public class TrainingDataParser
{
	public static IDataSet parseTrainingData(File file) throws IOException
	{

		IDataSet dataSet = new DataSet();
		BufferedReader reader = null;

		try
		{
			reader = new BufferedReader(new FileReader(file));

			String line;
			String[] valueTexts;
			double[] values;

			line = reader.readLine();
			String names[] = line.trim().split("\\t");

			for (String header : names)
			{
				dataSet.addNeuronName(header);
			}

			while ((line = reader.readLine()) != null)
			{
				valueTexts = line.trim().split("\\t");
				values = new double[valueTexts.length];
				for (int i = 0; i < valueTexts.length; i++)
				{
					double value = Double.parseDouble(valueTexts[i]);
					values[i] = value;
				}
				dataSet.addDataRow(values);
			}
		}
		finally
		{
			if (reader != null)
				reader.close();
		}

		return dataSet;
	}
}
